package servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import service.UserService;
import service.UserServiceImpl;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name="deleteServlet",urlPatterns = "/deleteServlet")
public class deleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out= response.getWriter();
        UserService userService=new UserServiceImpl();
        String num=request.getParameter("uNum");
        boolean result=userService.deleteUser(num);
        if(result) {
            out.print("<script>alert('删除成功');window.location.href='queryAllServlet'</script>" );
        } else
            out.print("<script>alert('删除失败');window.location.href='queryAllServlet'</script>" );

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
